import random


def check(dl):
    count_0 = len(list(filter(lambda x: x == 0, dl)))
    count_1 = len(list(filter(lambda x: x == 1, dl)))
    count_2 = len(list(filter(lambda x: x == 2, dl)))
    c1n = max(3 - count_1, 0)
    c2n = max(3 - count_2, 0)
    r = count_0 >= c1n + c2n
    # if r:
    #     print(dl)
    #     print(r)
    return r


def re_roll(dl):
    count_1 = 0
    count_2 = 0
    for i in range(len(dl)):
        if dl[i] == 0:
            continue
        elif dl[i] == 1 and count_1 < 3:
            count_1 += 1
        elif dl[i] == 2 and count_2 < 3:
            count_2 += 1
        else:
            dl[i] = random.randint(0, 7)
    return dl


times = 1000000
aim = 0
for _ in range(times):
    dice_list = [random.randint(0, 7) for _ in range(8)]
    re_roll(dice_list)
    if check(dice_list):
        aim += 1
print()
print(aim)
print(aim / float(times))
